<?php
/**
 * 客服
 */

namespace App\Services\cs;

use App\Models\Common\Cs;
use App\Services\Com\UtilService;

class CsService
{
    /**
     * 计算我的专属客服id 
     * 目前设x个客服坐席，取模x，轮流匹配属于某用户的客服id
     * var_dump(1%3); 1
     * var_dump(2%3); 2
     * var_dump(3%3); 0
     * var_dump(4%3); 1
     * 
     * 如果加客服坐席，则在根据新加坐席的时候，做大于某个uid后，再划分
     * 更换客服uuid 聊天记录要重新拉
     **/
    public static function MyCsHandle(string $uid = '')
    {
        $cs_res = Cs::where('state', '=', '1')->get();
        $cs_uuids = $cs_res->toArray();
        $cs_uuids_arr = array_column($cs_uuids, 'member_uuid');
        
        $cs_mod = 3;
        $cs_mod_10K = 4;

        $cs_uuid = $cs_uuids_arr[0];

        //小于1万用户，坐席取模
        if($uid <= 10000){
            $uid_mod = intval($uid % $cs_mod);
            if($cs_uuids_arr[$uid_mod]){
                $cs_uuid = $cs_uuids_arr[$uid_mod];
            }
        }

        //大于1万用户，坐席取模
        if($uid > 100000){
            $uid_mod = intval($uid % $cs_mod);
            if($cs_uuids_arr[$uid_mod]){
                $cs_uuid = $cs_uuids_arr[$uid_mod];
            }
        }

        $res['cs_uuid'] = $cs_uuid;
        $res['cs_im_username'] = UtilService::memberUuidToImAccount($cs_uuid);
        return $res;
        
    }

    
}

?>

